<?PHP
class MHDEV_View_Helper_Navigation extends Zend_View_Helper_Abstract
{
	public function Navigation(array $options = NULL)
	{
		$output = ''; # init
		
		$auth		= Zend_Auth::getInstance();
		
		$request 	= Zend_Controller_Front::getInstance();
		$view 		= Zend_Layout::getMvcInstance()->getView();
		$action 	= $request->getRequest()->getActionName();
		$controller	= $request->getRequest()->getControllerName();
		
		$db 	= Zend_Registry::get('db');	
		$result = $db->query('SELECT * FROM `navigation` WHERE `hidden` = 0 ORDER BY `sort_id`');
		$rows 	= $result->fetchAll();
		
		foreach($rows AS $row) 
		{
			if($row['role'] != "")
			{
				$role = explode(',', $row['role']);
				
				if(!$auth->hasIdentity() OR !in_array($auth->getIdentity()->role,$role))
				{
					continue;
				}
			}
			
			if($controller == $row['controller']) 
			{
				$cssStyle = 'class="main_act"';
			}
			else
			{
				$cssStyle = 'class="main_no"';
			}
			
			$output .= '
			<li ' . $cssStyle . '>
				<a ' . $cssStyle . ' href="' . $view->url(array('module' => $row['controller'], 'action' => $row['action']),$row['controller'],true). '">' . $row['title'] . '</a>	
			</li>';
		}
		
		return $output;
	}
}